//
//  MainTabBarController.m
//  SHOP
//
//  Created by L on 2017/10/8.
//  Copyright © 2017年 L. All rights reserved.
//

#import "MainTabBarController.h"
#import "MainNavigationController.h"

@interface MainTabBarController ()

@property (nonatomic, assign)NSInteger num;

@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.num = 1;
    
    NSArray *titleArr = @[@{@"vc":@"HomeViewController",@"image":@"首页",@"title":@"首页"},@{@"vc":@"ThreeViewController",@"image":@"叉",@"title":@"三免一"},@{@"vc":@"TicketViewController",@"image":@"活动中心",@"title":@"领卷中心"},@{@"vc":@"ShoppingViewController",@"image":@"购物车",@"title":@"购物车"},@{@"vc":@"MeViewController",@"image":@"我的",@"title":@"我的"}];
    
    NSMutableArray *arrVC = [[NSMutableArray alloc] init];
    for (NSDictionary *dict in titleArr)
    {
        UIViewController *vc = [self getVC:dict[@"vc"] Image:dict[@"image"] Title:dict[@"title"]];
        [arrVC addObject:vc];
    }
    
    self.tabBar.tintColor = kTabbarTitleColor;
    self.viewControllers = arrVC;
    self.tabBar.translucent = NO;
}

- (UIViewController *)getVC:(NSString *)clsName Image:(NSString *)image Title:(NSString *)title
{
    Class cls = NSClassFromString(clsName);
    UIViewController *vc = [[cls alloc] init];
    
    NSString *imageNormal = [NSString stringWithFormat:@"%@",image];
    NSString *imageSelected = [NSString stringWithFormat:@"%@",image];
    vc.tabBarItem.image = [UIImage imageNamed:imageNormal];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:imageSelected] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    MainNavigationController *nav = [[MainNavigationController alloc] initWithRootViewController:vc];
    
    if (self.num == 1)
    {
        vc.tabBarItem.title = title;
        self.num ++;
        return nav;
    }
    
    vc.title = title;
    
    return nav;
}

@end
